<template>
<<<<<<< HEAD
  <div class='container'>标签管理</div>
</template>

<script>
export default {}
</script>

<style scoped lang='less'></style>
=======
  <!-- 第三页 每页必用 -->
  <div class="dashboard-container">
    <div class="xk-container">
      <el-card shadow="never">
        <!-- 面包屑导航 -->
        <el-breadcrumb separator="/" v-if="id">
          <el-breadcrumb-item>学科管理</el-breadcrumb-item>
          <el-breadcrumb-item>{{ $route.query.data }}</el-breadcrumb-item>
          <el-breadcrumb-item>标签管理</el-breadcrumb-item>
        </el-breadcrumb>
        <!-- 面包屑导航 /-->
        <el-form :inline="true" class="demo-form-inline">
          <el-form-item label="标签名称">
            <el-input size="small" v-model="queryInfo.tagName" @clear="getList"></el-input>
          </el-form-item>
          <el-form-item label="状态" class="left-input">
            <el-select v-model="queryInfo.state" placeholder="请选择" size="small">
              <el-option label="启用" size="small" value="1"></el-option>
              <el-option label="禁用" size="small" value="0"></el-option>
            </el-select>
            <el-button class="filter-item left-button" size="small" @click="clearlist">{{ $t('table.clear') }}</el-button>
            <el-button class="filter-item" size="small" type="primary" @click="getList">{{ $t('table.search') }}</el-button>
          </el-form-item>
          <el-button class="filter-item filter-right" size="small" style="margin-left: 10px" @click="addDialog = true" type="success" icon="el-icon-edit">{{ $t('table.xzbq') }}</el-button>
          <el-button type="text" v-if="id" class="filter-right" @click="$router.back()" icon="el-icon-back">返回学科</el-button>
        </el-form>
        <!-- 灰色提示 -->
        <div>
          <el-alert :title="alertText" type="info" show-icon :closable="false" class="alert"> </el-alert>
        </div>
        <!-- 渲染列表 -->
        <el-table :data="datalist" style="width: 100%">
          <el-table-column rowspan="1" type="index" label="序号" width="50"> </el-table-column>
          <el-table-column rowspan="1" prop="subjectName" label="所属学科"> </el-table-column>
          <el-table-column rowspan="1" prop="tagName" label="标签名称"> </el-table-column>
          <el-table-column rowspan="1" prop="username" label="创建者"> </el-table-column>
          <el-table-column rowspan="1" label="创建日期" width="200">
            <template slot-scope="scope">
              {{ scope.row.addDate | parseTimeByString }}
            </template>
          </el-table-column>
          <el-table-column rowspan="1" label="状态">
            <template slot-scope="scope">
              {{ scope.row.state ? '已启用' : '已禁用' }}
            </template>
          </el-table-column>
          <el-table-column width="240" prop="address" label="操作">
            <template slot-scope="scope">
              <el-link type="primary" @click="stop(scope.row)">{{ scope.row.state ? '禁用' : '启用' }}</el-link>
              <el-link :type="scope.row.state ? 'info' : 'primary'" :underline="false" :disabled="scope.row.state ? true : false" @click="handle(scope.row)">修改</el-link>
              <el-link :type="scope.row.state ? 'info' : 'primary'" :underline="false" :disabled="scope.row.state ? true : false" @click="deleteID(scope.row.id)">删除</el-link>
            </template>
          </el-table-column>
        </el-table>
        <!-- 渲染列表 -->
        <!-- 页签列表 -->
        <div class="block">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="queryInfo.page"
            :page-sizes="[5, 10, 20, 30]"
            :page-size="queryInfo.pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          >
          </el-pagination>
        </div>
      </el-card>
    </div>
    <!----------------------------- 弹出框 ------------------------------>
    <!-- 添加用户输入框弹出 -->
    <el-dialog title="新增标签" :visible.sync="addDialog" width="25%">
      <!-- 内容主体 -->
      <el-form :model="addFrom" :rules="addFromrules" label-width="100px">
        <el-form-item label="所属学科" v-if="!id">
          <el-select v-model="addFrom.subjectID" placeholder="请选择" size="small" style="width: 250px">
            <el-option v-for="index in jdlist" :label="index.label" :value="index.value" size="small" :key="index.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="标签名称" prop="tagName">
          <el-input v-model="addFrom.tagName" placeholder="请输入标签" style="width: 250px"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer">
        <el-button @click="addDialog = false">取 消</el-button>
        <el-button type="primary" @click="addUser">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 修改修改用户输入框弹出 -->
    <el-dialog title="修改学科" :visible.sync="updateDialog" width="25%">
      <!-- 内容主体 -->
      <el-form :model="updateFrom" :rules="updateFromrules" label-width="100px">
        <el-form-item label="所属学科" v-if="!id">
          <el-select v-model="updateFrom.subjectName" placeholder="请选择" size="small" style="width: 250px">
            <el-option v-for="index in jdlist" :label="index.label" :value="index.value" size="small" :key="index.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="标签名称" prop="tagName">
          <el-input v-model="updateFrom.tagName" placeholder="请输入目录" style="width: 250px"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer">
        <el-button @click="updateDialog = false">取 消</el-button>
        <el-button type="primary" @click="updateUser">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { list, add, update, remove, changeState } from '@/api/hmmm/tags'
import { simple } from '@/api/hmmm/subjects'
export default {
  name: 'tags',
  computed: {},
  data() {
    return {
      queryInfo: {
        tagName: '',
        // 当前页数
        page: 1,
        // 当前每页几条
        pagesize: 5,
        // 下拉状态
        state: null
      },
      jdqueryInfo: {
        subjectID: ''
      },
      // 定义空列表
      datalist: [],
      // 简单列表
      jdlist: [],
      // 当前多少数据
      total: 0,
      // 灰色一共多少数据
      alertText: '',
      // 添加对话框后隐藏
      id: this.$route.query.id,
      addDialog: false,
      addFrom: {
        tagName: '',
        subjectID: null
      },
      // 修改对话框后隐藏
      updateFrom: {
        id: null,
        tagName: '',
        isFrontDisplay: null
      },
      // 修改对话框隐藏
      updateDialog: false,
      value: '',
      // 表单添加验证
      addFromrules: {
        tagName: [{ required: true, message: '请输入用户名', trigger: 'blur' }]
      },
      // 表单修改验证
      updateFromrules: {
        tagName: [{ required: true, message: '请输入用户名', trigger: 'blur' }]
      }
    }
  },
  props: {},
  created() {
    // 表单渲染
    this.getList()
    this.jdlistitem()
  },
  mounted() {},
  methods: {
    stop(row) {
      changeState({
        id: row.id,
        state: row.state ? 0 : 1
      })
        .then((data) => {
          row.state = row.state ? 0 : 1
        })
        .catch((eee) => {
          this.$message.eee('错了错了')
        })
    },
    // 清除按钮
    clearlist() {
      this.queryInfo.tagName = ''
      this.queryInfo.state = null
    },
    // 简单列表
    async jdlistitem() {
      const { data: res } = await simple()
      this.jdlist = res
    },
    // 表单目录
    async getList() {
      if (this.id == null) {
        list(this.queryInfo)
          .then((data) => {
            this.datalist = data.data.items
            this.total = data.data.counts
            this.alertText = `数据一共有${this.total}条`
          })
          .catch((e) => {
            this.$message('da')
          })
      } else {
        const res = await list({ subjectID: this.id })
        this.datalist = res.data.items
        this.total = res.data.counts
        this.alertText = `数据一共有${this.total}条`
      }
    },
    handleSizeChange(val) {
      this.queryInfo.pagesize = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.queryInfo.page = val
      this.getList()
    },
    // 添加目录
    addUser() {
      add({
        subjectID: this.addFrom.subjectID ? this.addFrom.subjectID : this.id,
        tagName: this.addFrom.tagName
      })
        .then((data) => {
          this.$message.success('添加标签成功')
          this.getList()
        })
        .catch((e) => {
          this.$message('添加标签失败')
        })
      this.addFrom.tagName = ''
      this.addFrom.subjectID = null
      this.addDialog = false
    },
    // 修改目录
    updateUser() {
      update(this.updateFrom)
        .then((e) => {
          this.$message.success('修改目录成功')
          this.getList()
        })
        .catch((e) => {
          this.$message('修改目录失败')
        })
      this.updateDialog = false
    },
    handle(val) {
      this.updateDialog = true
      this.updateFrom.id = val.id
      this.updateFrom.subjectID = val.subjectID
      this.updateFrom.tagName = val.tagName
      this.updateFrom.isFrontDisplay = val.isFrontDisplay ? true : false
    },
    // 删除学科
    deleteID(id) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          const res = await remove({ id })
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
          this.getList()
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    }
  }
}
</script>

<style scoped lang="less">
.filter-input {
  margin: 0 20px;
}
.filter-right {
  float: right;
}
.alert {
  margin-bottom: 20px;
}
.block {
  margin: 20px;
}
.textname {
  font-size: 14px;
  font-weight: 800;
}
.textnamel,
.left-input {
  margin-left: 50px;
}
.left-button {
  margin-left: 20px;
}
.el-link {
  margin-right: 20px;
}
</style>
>>>>>>> 99b581ad90efc8af6413e4097d13ec8f4855db58
